# hnol_pop_rss.sh now incorporates horizontal/vertical judging and resizing&zip function all in one!       
# dependency: GNU wget (busybox wget cannot work); imagicmagick for mogrify                            
wget -O index_hnol_rss.htm "http://bbs.voc.com.cn/forumdisplay.php?fid=50&filter=172800&orderby=views"
                                                                                                      
sticktop=` cat index_hnol_rss.htm |grep pin_1|wc -l ` #pin_1.gif indicates a sticky_stop post 
firstpost=+` expr $sticktop + 1 ` #assume sticktop=6 post, then tail -n +7 shows starting 7th post, which is real.
                                                                                                                  
cat index_hnol_rss.htm | grep "href=\"topic" | grep "1-1.html" | tail -n $firstpost | head -10 > links_hnol_rss.htm
#cat index_hnol_rss.htm | grep "1-1.html" | awk -F "title" '{print $1}' | tail -n $firstpost | head -10 > links_hnol_rss.htm 

sed -i -e "s/-1-1.html.*/.html/g" links_hnol_rss.htm                                                   
sed -i -e "s/.*topic/http:\/\/bbs.voc.com.cn\/archiver\/tid/g" links_hnol_rss.htm                      
                                                                                                       
wget -nd -r -Dimage.hnol.net,bbs.voc.com.cn -l1 -A jpg -H -i links_hnol_rss.htm                        
                                                                                                       
#identify_jpg_hori_vert_resize embeded here to make it portable (run within 1 dir, any dir)            
rm -f hnol_*rss*.zip                                                                                    
                                                                                                       
find . -name "*.jpg" | while read jpgfilename; do                                                      
    xsize=`identify -ping $jpgfilename | sed -e "s/.*JPEG //g" | sed -e "s/x.*//g"`                    
    ysize=`identify -ping $jpgfilename | sed -e "s/.*JPEG [0-9]*x//g" | sed -e "s/\ [0-9]*x.*//g"`     
                                                                                                       
    if [ $xsize -ge $ysize ] ; then                                                                    
        if [ $xsize -ge 500 ] ; then                                                                   
                mogrify -resize 480x320 $jpgfilename                                                   
        fi                                                                                             
        zip ./hnol_pop_rss_hori.zip $jpgfilename >/dev/null;                                               
    else                                                                                               
        if [ $ysize -ge 500 ] ; then                                                                   
                mogrify -resize 320x480 $jpgfilename                                                   
        fi                                                                                             
        zip ./hnol_pop_rss_vert.zip $jpgfilename >/dev/null;                                               
    fi                                                                                                 
done                                                                                                   
                                                                                                       
rm -f *.jpg                                                                                            
#/identify_jpg_hori_vert_resize embeded here to make it portable (run in 1 dir, any dir)               
